using UnityEngine;

/// <summary>
/// 调试渲染Camera的Frustum
/// </summary>
public class DrawFrustum : MonoBehaviour
{
    public bool Enable = true;

    private Camera target;

    public Camera Target
    {
        get
        {
            if (target == null)
            {
                target = GetComponent<Camera>();
            }
            return target;
        }
    }

    private void OnDrawGizmos()
    {
        if (Enable)
        {
            Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale);
            Gizmos.DrawFrustum(Vector3.zero, Target.fieldOfView, Target.farClipPlane, Target.nearClipPlane, Target.aspect);
        }
    }
}